"use strict"

module.exports = function(options){
  var _ = require("lodash");
  
  var QywxAccessTokenHolder = function(options){
    if( !(this instanceof QywxAccessTokenHolder) ){
      return new QywxAccessTokenHolder(options);
    }else{
      this.options = options;
    }
  }

  QywxAccessTokenHolder.prototype.set = function(accessToken, expiresIn) {
    this.token       = accessToken;
    this.expiresIn   = expiresIn;
    this.expiresAt   = _.now() + expiresIn * 1000;
  };

  QywxAccessTokenHolder.prototype.expiring = function(){
    return !!( (this.expiresAt - _.now()) < 5 * 60 * 1000 );
  }

  QywxAccessTokenHolder.prototype.expired = function(){
    return !!( this.expiresAt < _.now() );
  }

  return new QywxAccessTokenHolder(options);
}
